package com.example.javaspringweb.controller;

import com.example.javaspringweb.entity.DataDemo;
import com.example.javaspringweb.service.DataServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class DataController {

    @Resource
    private DataServiceImpl dataServiceImpl;

    @GetMapping("/dataB")  // @RequestMapping(method = RequestMethod.GET)的缩写。
    public String getAllData(Model model){
        List<DataDemo> allData = dataServiceImpl.getAll();
        model.addAttribute("allData",allData);
        return "emps/list_b";
    }

//    @RequestMapping("/dataC")  // @RequestMapping可以指定GET、POST请求方式
    @GetMapping("/dataC")
    public String getRegionData(
            @RequestParam String region,
            Model model
    ){
        List<DataDemo> region1 = dataServiceImpl.getRegion(region);
        model.addAttribute("dataC",region1);
        return "emps/list_c";
    }



}
